package com.smile.service.entity.config;

import com.alibaba.fastjson2.annotation.JSONField;

public class DeviceAppConfig {

    @JSONField(name = "app_id")
    private String appId;

    @JSONField(name = "app_key")
    private String appKey;

    @JSONField(name = "app_license")
    private String appLicense;

    @JSONField(name = "ntp_server_host",serialize = false)
    private String ntpServerHost;

    @JSONField(name = "ntp_server_port",serialize = false)
    private int ntpServerPort;

    // 无参构造
    public DeviceAppConfig() {
    }

    // 全参构造
    public DeviceAppConfig(String appId, String appKey, String appLicense,
                           String ntpServerHost, int ntpServerPort) {
        this.appId = appId;
        this.appKey = appKey;
        this.appLicense = appLicense;
        this.ntpServerHost = ntpServerHost;
        this.ntpServerPort = ntpServerPort;
    }

    // Getter & Setter
    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getAppLicense() {
        return appLicense;
    }

    public void setAppLicense(String appLicense) {
        this.appLicense = appLicense;
    }

    public String getNtpServerHost() {
        return ntpServerHost;
    }

    public void setNtpServerHost(String ntpServerHost) {
        this.ntpServerHost = ntpServerHost;
    }

    public int getNtpServerPort() {
        return ntpServerPort;
    }

    public void setNtpServerPort(int ntpServerPort) {
        this.ntpServerPort = ntpServerPort;
    }

    // 实用方法 - 获取完整的NTP服务器地址
    public String getNtpFullAddress() {
        return ntpServerHost + ":" + ntpServerPort;
    }

    // 实用方法 - 验证应用配置完整性
    public boolean isConfigComplete() {
        return appId != null && !appId.isEmpty() &&
                appKey != null && !appKey.isEmpty() &&
                appLicense != null && !appLicense.isEmpty() &&
                ntpServerHost != null && !ntpServerHost.isEmpty() &&
                ntpServerPort > 0;
    }

    // 实用方法 - 重设配置信息
    public void resetConfig(String newAppId, String newAppKey, String newAppLicense) {
        this.appId = newAppId;
        this.appKey = newAppKey;
        this.appLicense = newAppLicense;
        // 保持NTP配置不变
    }

    @Override
    public String toString() {
        return "DeviceAppConfig[" +
                "appId='" + appId + '\'' +
                ", appKey='[PROTECTED]'" + // 敏感信息不显示
                ", appLicense='[PROTECTED]'" + // 敏感信息不显示
                ", ntpServerHost='" + ntpServerHost + '\'' +
                ", ntpServerPort=" + ntpServerPort +
                ']';
    }

    // 日志安全输出
    public String toLogString() {
        return "DeviceAppConfig{" +
                "appId='" + appId + '\'' +
                ", ntpServer='" + getNtpFullAddress() + '\'' +
                ", isComplete=" + isConfigComplete() +
                '}';
    }
}
